package thread;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i <1000 ; i++) {
                synchronized (list){
                    list.add(i);
                }
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i <1000 ; i++) {
                synchronized (list){
                    list.add(i);
                }
            }
        });
        try {
            t1.start();
            t2.start();
            Thread.sleep(1000);
            System.out.println(list.size());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }
}
